package pro.cherish.knowledgeumldesignpattern.designPattern.com.cherish.prototype;

import java.io.*;
import java.util.Date;

/**&
 * 使用序列化和反序列化实现深复制
 */
public class client3 {
    public static void main(String [] args) throws Exception {
        Date date=new Date(12312321331L);
        Sheep3 doli = new Sheep3("多利", date);
        System.out.println(doli);

//      使用序列化和反序列化实现深复制
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(doli);
        byte[] bytes = bos.toByteArray();

        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(bis);
        Sheep3 Sheep3=(Sheep3) ois.readObject();//克隆好的对象

        date.setYear(2018);
        System.out.println(doli);
        System.out.println(Sheep3);
    }
}
